﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace InpatientManagementSystem
{
    public partial class Form5 : Form
    {
        MySqlConnection myConnection = new MySqlConnection("server=localhost;user=root;password=786452as;database=zhuyuan;port=3306;charset=utf8");
        public Form5()
        {
            InitializeComponent();
        }
        Boolean flag = false;
        Boolean Flag = false;
        public Boolean getFlag()
        {
            return flag;
        }
        public Boolean GetFlag()
        {
            return Flag;
        }
        public void setFlag(Boolean i)
        {
            flag = i;
        }
        private void check()
        {
            myConnection.Open();
            string query = "select password,role from login where id = " + textBox1.Text;
            MySqlCommand myCommand = new MySqlCommand(query, myConnection);
            MySqlDataReader myReader = myCommand.ExecuteReader();
            try
            {
                if (!myReader.Read())
                {
                    MessageBox.Show("没有该账号！");
                }
                else
                {
                    if (textBox2.Text == myReader.GetString(0))
                    {
                        if (myReader.GetString(1) == "1")
                        {
                            setFlag(true);
                        }
                        Flag = true;
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("密码错误！");
                    }
                }
            }
            finally
            {
                myReader.Close();
                myConnection.Close();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            check();
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(System.Windows.Forms.Keys.Enter))
            {
                check();
            }
        }
    }
}
